package com.xianguo.datacenter.thread;

import java.util.List;
import java.util.UUID;

import com.xianguo.datacenter.domain.CenterFile;
import com.xianguo.datacenter.domain.CenterFolder;
import com.xianguo.datacenter.service.CommonService;

public class FileReadThread implements Runnable {
	
	private CommonService commonService;
	
	private String path;
	
	public FileReadThread(String path,CommonService commonService) {//初始文件夹路径
		this.path = path;
		this.commonService = commonService;
	}
	
	@Override
	public void run() {
		readFile(path);
	}
	
	public void readFile(String path) {
		try {
			CenterFolder folders = commonService.getFolder(path);
			List<CenterFile> files = folders.getFiles();
			for(CenterFile item : files) {
				System.out.println(item.getName()+"----"+item.getPath());
				item.setId(UUID.randomUUID().toString().replace("-", ""));
				commonService.insertFile(item);
			}
			List<CenterFolder> folderList = folders.getFolders();
			for(CenterFolder item : folderList) {
				readFile(item.getPath());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
}
